import { defineComponent, watch, ref } from 'vue'
// 声明类型
const PropsType = {
  cdata: {
    type: Object,
    require: true
  }
} as const

// 定义主体
export default defineComponent({
  props: PropsType,
  setup(props) {
    // 定义 ref
    const chartRef = ref()
    // 配置项
    let options = {}

    // 监听
    watch(
      () => props.cdata,
      (val: any) => {
        options = {
          series: [
            {
              type: 'gauge',
              startAngle: 90,
              endAngle: -270,
              pointer: {
                show: false
              },
              progress: {
                show: true,
                overlap: false,
                roundCap: true,
                clip: false,
                itemStyle: {
                  borderWidth: 1,
                  borderColor: 'none',
                }
              },
              axisLine: {
                lineStyle: {
                  width: 20,
                  color:[[1,'#70909f52']]
                }
              },
              splitLine: {
                show: false,
                distance: 0,
                length: 10
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                show: false,
                distance: 50
              },
              data: val.gaugeData,
              title: {
                fontSize: 9
              },
              detail: {
                width: 16,
                height: 6,
                fontSize: 16,
                color: 'inherit',
                borderColor: 'inherit',
                // borderRadius: 20,
                // borderWidth: 1,
              }
            }
          ]
        }
        // 手动触发更新
        if (chartRef.value) {
          // 通过初始化参数打入数据
          chartRef.value.initChart(options)
        }
      },
      {
        immediate: true,
        deep: true
      }
    )

    return () => {
      const height = "170px"
      const width = "170px"

      return <div>
        <echart ref={chartRef} height={height} width={width} />
      </div>
    }
  }
})

